package com.uwantsoft.util.paging;

import org.displaytag.pagination.PaginatedList;
import org.displaytag.properties.SortOrderEnum;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Ran Yuanyuan
 */
public class DefaultPaginatedList implements PaginatedList {

    protected AbstractOverviewQueryCondition queryCondition = new AbstractOverviewQueryCondition();

    protected List list;

    protected int fullListSize;

    protected Map<String, Object> otherDataMap = new HashMap<String, Object>();


    public DefaultPaginatedList(AbstractOverviewQueryCondition queryCondition) {
        this.queryCondition = queryCondition;
    }


    public List getList() {
        return list;
    }

    public int getPageNumber() {
        return queryCondition.getPage();
    }

    public int getObjectsPerPage() {
        return queryCondition.getObjectsPerPage();
    }

    public int getFullListSize() {
        return fullListSize;
    }

    public String getSortCriterion() {
        return queryCondition.getSortCriterion();
    }

    public SortOrderEnum getSortDirection() {
        return queryCondition.getSortDirection();
    }

    public AbstractOverviewQueryCondition getQueryCondition() {
        return queryCondition;
    }

    public String getSearchId() {
        return null;
    }

    public DefaultPaginatedList loadData(PagingListLoader pagingListLoader) {
        this.fullListSize = pagingListLoader.loadFullListSize();
        this.list = pagingListLoader.loadList();
        pagingListLoader.loadOtherData(otherDataMap);
        return this;
    }

    public Map<String, Object> getOtherDataMap() {
        return otherDataMap;
    }

}
